/*
  StepperDriver.h - Library for controlling a stepper motor driver that takes
  a square wave signal on a STEP pin to step. This library was developed
  specifically for the Arduino Mega 2560 to interface with a Pololu DRV8825
  Stepper Motor Driver Carrier, High Current (md20a).
  
  Created by the STA team at UMBC on 17 January 2013.
*/

// ensure this library description is only included once
#ifndef StepperDriver_h
#define StepperDriver_h


// library interface description
class StepperDriver {
   public:
      StepperDriver(int oPin_STEP, int oPin_DIR, int oPin_SLP, int oPin_RST, 
         int oPin_M0, int oPin_M1, int oPin_M2, int oPin_EN);
      long smartStep(long numSteps);
      long smartStep(long numSteps, int sPS, int sPSPS);
      long stepAccelerate(long numSteps, int stepSize, int startingSPS, 
               int sPSPS);
      long step(long numSteps, int stepSize, int sPS);
      int stepMotor();
      // long stepToPosition(float newPos);
      void setStepMode(int stepMode);
      void setDirection(int direction);
      void enableDriver();
      void disableDriver();

      int getDirection();
      long getTimeLastStep();

      int version();

      static const int CLOCKWISE = 1;
            // clockwise rotation corresponds with DIR signal LOW
      static const int COUNTERCLOCKWISE = -1;
            // counter-clockwise rotation corresponds with DIR signal HIGH

      static const int steadyStageIndex = 5;
      static const int precisionStageIndex = 11;
      static const int numStages = 12;

   private:
      // void updateCurrPos(long stepsMoved);
      void initializeDriver();
      
      int direction;          // motor direction
      int stepMode;           // current step mode
      long timeLastStep;      // time stamp in ms of the last step taken

      int motorMaxSPS;
      int motorMinSPS;
      int motorMaxSPSPS;
      
      // Pin numbers for the motor control connection
      int oPin_STEP;
      int oPin_DIR;
      int oPin_SLP;
      int oPin_RST;
      int oPin_M0;
      int oPin_M1;
      int oPin_M2;
      int oPin_EN;
};

#endif

